package com.wdf.dota;

import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import com.wdf.bean.Equipment;
import com.wdf.bean.Info;

public class HeroEquiActivity extends Activity {


	

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.hero_equi);

		try {
		Bundle bundle = this.getIntent().getExtras();
		String heroname =	bundle.getString("heroname");
 
            Info info =new Info();
            Equipment equi = new Equipment();

            String[] start = info.getClass().getField(heroname+"_1").get(info).toString().split("-");
            String[] medium = info.getClass().getField(heroname+"_2").get(info).toString().split("-");
            String[] end = info.getClass().getField(heroname+"_3").get(info).toString().split("-");
            
            /*for(int i= 0;i< start.length; i++){
            	ImageView  startequipmentmap = (ImageView ) findViewById(getResources().getIdentifier("startequipment"+(i+1), "id", "com.wdf.dota"));
            	int id = getResources().getIdentifier("store"+start[i], "drawable", "com.wdf.dota"); 
    			Drawable startequipmentDrawable = getResources().getDrawable(id);
    			startequipmentmap.setBackgroundDrawable(startequipmentDrawable);
    			try {
					final String des =  equi.getClass().getField("store"+start[i]).get(equi).toString();
					if(des != null){
						startequipmentmap.setOnClickListener(new OnClickListener(){
							@Override
							public void onClick(View v) {
								final MyDialog dialog = new MyDialog(HeroEquiActivity.this, R.style.MyDialog);
							//	dialog.setProperty(400, 600);
							     dialog.setContentView(R.layout.dialog);
							     dialog.setTitle("");
							     dialog.setContent(Html.fromHtml(des));
									dialog. setPositiveButton("    ", new android.view.View.OnClickListener() {
										public void onClick(View v) {
											dialog.dismiss();
										}
									    });
							     dialog.show();
							}
	            			
	            		}); }
				} catch (Exception e) {
					e.printStackTrace();
				}
    			
    			
            }
            for(int i= 0;i< medium.length; i++){
            	ImageView  mediumequipmentmap = (ImageView ) findViewById(getResources().getIdentifier("mediumequipment"+(i+1), "id", "com.wdf.dota"));
            	int id = getResources().getIdentifier("store"+medium[i], "drawable", "com.wdf.dota"); 
    			Drawable mediumequipmentDrawable = getResources().getDrawable(id);
    			mediumequipmentmap.setBackgroundDrawable(mediumequipmentDrawable);
    			try {
					final String des =  equi.getClass().getField("store"+medium[i]).get(equi).toString();
					if(des != null){
						mediumequipmentmap.setOnClickListener(new OnClickListener(){
							@Override
							public void onClick(View v) {
								final MyDialog dialog = new MyDialog(HeroEquiActivity.this, R.style.MyDialog);
							//	dialog.setProperty(400, 600);
							     dialog.setContentView(R.layout.dialog);
							     dialog.setTitle("");
							     dialog.setContent(Html.fromHtml(des));
									dialog. setPositiveButton("    ", new android.view.View.OnClickListener() {
										public void onClick(View v) {
											dialog.dismiss();
										}
									    });
							     dialog.show();
							}
	            			
	            		}); }
				} catch (Exception e) {
					e.printStackTrace();
				}
            }
            
            for(int i= 0;i< end.length; i++){
            	ImageView  endequipmentmap = (ImageView ) findViewById(getResources().getIdentifier("endequipment"+(i+1), "id", "com.wdf.dota"));
            	int id = getResources().getIdentifier("store"+end[i], "drawable", "com.wdf.dota"); 
    			Drawable endequipmentDrawable = getResources().getDrawable(id);
    			endequipmentmap.setBackgroundDrawable(endequipmentDrawable);
    			try {
					final String des =  equi.getClass().getField("store"+end[i]).get(equi).toString();
					if(des != null){
						endequipmentmap.setOnClickListener(new OnClickListener(){
							@Override
							public void onClick(View v) {
								final MyDialog dialog = new MyDialog(HeroEquiActivity.this, R.style.MyDialog);
							//	dialog.setProperty(400, 600);
							     dialog.setContentView(R.layout.dialog);
							     dialog.setTitle("");
							     dialog.setContent(Html.fromHtml(des));
									dialog. setPositiveButton("   ", new android.view.View.OnClickListener() {
										public void onClick(View v) {
											dialog.dismiss();
										}
									    });
							     dialog.show();
							}
	            			
	            		}); }
				} catch (Exception e) {
					e.printStackTrace();
				}
            }*/
          //通过三个for循环部署图片
            for(int i= 0;i< start.length; i++){
            	final String equName= start[i];
            	ImageView  startequipmentmap = (ImageView ) findViewById(getResources().getIdentifier("startequipment"+(i+1), "id", "com.wdf.dota"));
            	InputStream fis;
    			try {
    				fis = getAssets().open( "dota/store"+start[i] +".png");
    				Bitmap bm = BitmapFactory.decodeStream(fis);
    				startequipmentmap.setImageBitmap(bm);
					/*startequipmentmap.setOnClickListener(new OnClickListener(){
							@Override
							public void onClick(View v) {
								      showDisplay(equName);
							}
	            			
	            		}); */
    				final String des =  equi.getClass().getField("store"+start[i]).get(equi).toString();
					if(des != null){
						startequipmentmap.setOnClickListener(new OnClickListener(){
							@Override
							public void onClick(View v) {
								final MyDialog dialog = new MyDialog(HeroEquiActivity.this, R.style.MyDialog);
							//	dialog.setProperty(400, 600);
							     dialog.setContentView(R.layout.dialog);
							     dialog.setTitle("");
							     dialog.setContent(Html.fromHtml(des));
									dialog. setPositiveButton("    ", new android.view.View.OnClickListener() {
										public void onClick(View v) {
											dialog.dismiss();
										}
									    });
							     dialog.show();
							}
	            			
	            		}); }
    			} catch (IOException e) {
    				e.printStackTrace();
    			}
            }
            for(int i= 0;i< medium.length; i++){
            	final String equName= medium[i];
            	ImageView  mediumequipmentmap = (ImageView ) findViewById(getResources().getIdentifier("mediumequipment"+(i+1), "id", "com.wdf.dota"));
            	InputStream fis;
    			try {
    				fis = getAssets().open( "dota/store"+medium[i] +".png");
    				Bitmap bm = BitmapFactory.decodeStream(fis);
    				mediumequipmentmap.setImageBitmap(bm);
    				/*mediumequipmentmap.setOnClickListener(new OnClickListener(){
						@Override
						public void onClick(View v) {
							      showDisplay(equName);
						}
            			
            		}); */
    				final String des =  equi.getClass().getField("store"+medium[i]).get(equi).toString();
					if(des != null){
						mediumequipmentmap.setOnClickListener(new OnClickListener(){
							@Override
							public void onClick(View v) {
								final MyDialog dialog = new MyDialog(HeroEquiActivity.this, R.style.MyDialog);
							//	dialog.setProperty(400, 600);
							     dialog.setContentView(R.layout.dialog);
							     dialog.setTitle("");
							     dialog.setContent(Html.fromHtml(des));
									dialog. setPositiveButton("    ", new android.view.View.OnClickListener() {
										public void onClick(View v) {
											dialog.dismiss();
										}
									    });
							     dialog.show();
							}
	            			
	            		}); }
    			} catch (IOException e) {
    				e.printStackTrace();
    			}
            }
            
            for(int i= 0;i< end.length; i++){
            	final String equName= end[i];
            	ImageView  endequipmentmap = (ImageView ) findViewById(getResources().getIdentifier("endequipment"+(i+1), "id", "com.wdf.dota"));
            	InputStream fis;
    			try {
    				fis = getAssets().open( "dota/store"+end[i] +".png");
    				Bitmap bm = BitmapFactory.decodeStream(fis);
    				endequipmentmap.setImageBitmap(bm);
    				/*endequipmentmap.setOnClickListener(new OnClickListener(){
						@Override
						public void onClick(View v) {
							      showDisplay(equName);
						}
            			
            		});*/
    				final String des =  equi.getClass().getField("store"+end[i]).get(equi).toString();
					if(des != null){
						endequipmentmap.setOnClickListener(new OnClickListener(){
							@Override
							public void onClick(View v) {
								final MyDialog dialog = new MyDialog(HeroEquiActivity.this, R.style.MyDialog);
							//	dialog.setProperty(400, 600);
							     dialog.setContentView(R.layout.dialog);
							     dialog.setTitle("");
							     dialog.setContent(Html.fromHtml(des));
									dialog. setPositiveButton("   ", new android.view.View.OnClickListener() {
										public void onClick(View v) {
											dialog.dismiss();
										}
									    });
							     dialog.show();
							}
	            			
	            		}); }
    			} catch (IOException e) {
    				e.printStackTrace();
    			}

            }

            
		} catch (Exception e) {
		}
		
		
	}
}
